package com.xiongxiong.yiqing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiongxiong.yiqing.api.CommonController;
import com.xiongxiong.yiqing.api.CommonResult;
import com.xiongxiong.yiqing.pojo.RecordCard;
import com.xiongxiong.yiqing.pojo.SysUser;
import com.xiongxiong.yiqing.pojo.vo.FindSysUserCondition;
import com.xiongxiong.yiqing.pojo.vo.RecordCardAddOrUpdateVO;
import com.xiongxiong.yiqing.pojo.vo.RecordCardVO;
import com.xiongxiong.yiqing.pojo.vo.SysUserVO;
import com.xiongxiong.yiqing.service.RecordCardService;
import com.xiongxiong.yiqing.service.SysUserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.smartcardio.Card;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 熊熊很酷
 * @since 2022-12-14
 */
@RestController
@RequestMapping("/card")
@Slf4j
public class RecordCardController extends CommonController {

    @Autowired
    private RecordCardService cardService;

    @ApiOperation("分页或帅选条件查询 userId=0表示查全部")
    @PostMapping("/recordList/{pageNub}/{pageSize}/{userId}")
    public CommonResult<Page<RecordCardVO>> recordList(@PathVariable("pageNub") Integer pageNub,
                                                                 @PathVariable("pageSize") Integer pageSize,
                                                                 @PathVariable(name = "userId") Integer id,
                                                                 @RequestBody(required = false) FindSysUserCondition findCondition) {

        return process(() -> cardService.recordList(pageNub, pageSize, id, findCondition));
    }


    @ApiOperation("打卡或修改 type=1打卡 2修改")
    @PostMapping("/updateOrAddRecord/{type}")
    public CommonResult<Boolean> updateOrAddRecord(@PathVariable("type") Integer type, @RequestBody RecordCardAddOrUpdateVO card) {
        log.info("打卡或修改={}", card);
        return process(() ->  cardService.updateOrAddRecord(type, card));
    }

    @ApiOperation("删除通过id")
    @GetMapping("/deleteRecordById/{id}")
    public CommonResult<Boolean> deleteRecordById(@PathVariable("id") Integer id) {
        return process(() ->  cardService.deleteRecordById(id));
    }

}
